package copyengine.ui.infoTree.buildTree
{
    import copyengine.infoTree.meta.CESAnimationEachFrameInfoMeta;
    import copyengine.infoTree.meta.CESDisplayObjectMeta;
    import copyengine.utils.CEStringUtils;

    import flash.geom.Matrix;
    import flash.utils.Dictionary;

    import starling.display.DisplayObject;

    public class InfoTreeBuildUtils
    {
        public function InfoTreeBuildUtils()
        {
        }

        public static function setBasicInfoByMeta(_meta:CESDisplayObjectMeta, _target:DisplayObject):void
        {
            if (_meta.frameTransformMatrixArray[0] != null) {
                var transform:Matrix = (_meta.frameTransformMatrixArray[0] as CESAnimationEachFrameInfoMeta).getMatrix();
                _target.transformationMatrix = transform;
            }
            _target.alpha = _meta.alpha;
            _target.name = _meta.name;
        }

        public static function addToQuickFindDic(_target:*, _dic:Dictionary, _quickFindKeyPR:String, _isRootNode:Boolean):void
        {
            if (_dic == null) {return;}

            if (_isRootNode) {
                _dic["root"] = _target;
            } else {
                if (!CEStringUtils.beginsWith(_target.name, "instance")) {
                    _dic[_quickFindKeyPR + "[" + _target.name + "]"] = _target;
                }
            }
        }

        public static function sortContainerSubChild(_subChildArray:Array):void { _subChildArray.sort(sortChildMetaByIndex)}

        private static function sortChildMetaByIndex(_a:CESDisplayObjectMeta, _b:CESDisplayObjectMeta):int
        {
            return _a.childIndex > _b.childIndex ? 1 : -1;
        }


    }
}
